package command;

import java.net.InetAddress;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.*;
import command.Command;
import command.CommandException;
import db.CommonConnect;

import common.CommonUtil;
import common.Crypto;
import common.EDUBOX_Baese64_Crypto;
import common.UserSession;
import db.QueryManager;
import db.DAO;

/**
 * Command 인터페이스를 implement 하여 구현된 command.
 */
public class TstestModifyCommand extends Command {

	private String next;
	
	public TstestModifyCommand(String next) {
		this.next=next;
	}

	/**
	 * 실제 요청을 받아 처리하는 메소드
	 * 요청을 받으면  요청을 처리하고 next 페이지를 돌려줌
	 * 
	 * @param req HttpServletRequest
	 * @throws CommandException
	 * @return next 이동할 페이지
	 */
	public String execute(HttpServletRequest req)
	throws CommandException {
		ArrayList list =  null;
		HashMap listMap = new HashMap();	
	
		Connection con = null;  
		try {		
			
			String user_id = CommonUtil.nvl(req.getParameter("user_id"));	
			String member_id = CommonUtil.nvl(req.getParameter("member_id"));	
			String member_test_code = CommonUtil.nvl(req.getParameter("member_test_code"));
			
			String q1_1 = CommonUtil.nvl(req.getParameter("q1_1"),"6");
			String q1_2 = CommonUtil.nvl(req.getParameter("q1_2"),"6");
			String q2_1 = CommonUtil.nvl(req.getParameter("q2_1"),"6");
			String q2_2 = CommonUtil.nvl(req.getParameter("q2_2"),"6");
			String q3_1 = CommonUtil.nvl(req.getParameter("q3_1"),"6");
			String q3_2 = CommonUtil.nvl(req.getParameter("q3_2"),"6");
			String q3_3 = CommonUtil.nvl(req.getParameter("q3_3"),"6");
			String q3_4 = CommonUtil.nvl(req.getParameter("q3_4"),"6");
			String q3_5 = CommonUtil.nvl(req.getParameter("q3_5"),"6");
			String q4_1 = CommonUtil.nvl(req.getParameter("q4_1"),"6");
			String q4_2 = CommonUtil.nvl(req.getParameter("q4_2"),"6");
			String q4_3 = CommonUtil.nvl(req.getParameter("q4_3"),"6");
			String q4_4 = CommonUtil.nvl(req.getParameter("q4_4"),"6");
			String q4_5 = CommonUtil.nvl(req.getParameter("q4_5"),"6");
			String q4_6 = CommonUtil.nvl(req.getParameter("q4_6"),"6");
			String q4_7 = CommonUtil.nvl(req.getParameter("q4_7"),"6");
			String q5_1 = CommonUtil.nvl(req.getParameter("q5_1"),"6");
			String q5_2 = CommonUtil.nvl(req.getParameter("q5_2"),"6");
			String q5_3 = CommonUtil.nvl(req.getParameter("q5_3"),"6");
			String q5_4 = CommonUtil.nvl(req.getParameter("q5_4"),"6");
			String q5_5 = CommonUtil.nvl(req.getParameter("q5_5"),"6");
			String q5_6 = CommonUtil.nvl(req.getParameter("q5_6"),"6");
			String q5_7 = CommonUtil.nvl(req.getParameter("q5_7"),"6");
			String q6_1 = CommonUtil.nvl(req.getParameter("q6_1"),"6");
			String q6_2 = CommonUtil.nvl(req.getParameter("q6_2"),"6");
			String q6_3 = CommonUtil.nvl(req.getParameter("q6_3"),"6");
			String q6_4 = CommonUtil.nvl(req.getParameter("q6_4"),"6");
			String q6_5 = CommonUtil.nvl(req.getParameter("q6_5"),"6");
			String q6_6 = CommonUtil.nvl(req.getParameter("q6_6"),"6");
			String q6_7 = CommonUtil.nvl(req.getParameter("q6_7"),"6");
			String q7_1 = CommonUtil.nvl(req.getParameter("q7_1"),"6");
			String q7_2 = CommonUtil.nvl(req.getParameter("q7_2"),"6");
			String q7_3 = CommonUtil.nvl(req.getParameter("q7_3"),"6");
			String q7_4 = CommonUtil.nvl(req.getParameter("q7_4"),"6");
			String q7_5 = CommonUtil.nvl(req.getParameter("q7_5"),"6");
			String q7_6 = CommonUtil.nvl(req.getParameter("q7_6"),"6");
			String q7_7 = CommonUtil.nvl(req.getParameter("q7_7"),"6");
			String q8_1 = CommonUtil.nvl(req.getParameter("q8_1"),"6");
			String q8_2 = CommonUtil.nvl(req.getParameter("q8_2"),"6");
			String q8_3 = CommonUtil.nvl(req.getParameter("q8_3"),"6");
			String q8_4 = CommonUtil.nvl(req.getParameter("q8_4"),"6");
			String q8_5 = CommonUtil.nvl(req.getParameter("q8_5"),"6");
			String q8_6 = CommonUtil.nvl(req.getParameter("q8_6"),"6");
			String q8_7 = CommonUtil.nvl(req.getParameter("q8_7"),"6");
			String q9_1 = CommonUtil.nvl(req.getParameter("q9_1"),"6");
			String q9_2 = CommonUtil.nvl(req.getParameter("q9_2"),"6");
			String q9_3 = CommonUtil.nvl(req.getParameter("q9_3"),"6");
			String q9_4 = CommonUtil.nvl(req.getParameter("q9_4"),"6");
			String q9_5 = CommonUtil.nvl(req.getParameter("q9_5"),"6");
			String q9_6 = CommonUtil.nvl(req.getParameter("q9_6"),"6");
			String q9_7 = CommonUtil.nvl(req.getParameter("q9_7"),"6");
			String q10_1 = CommonUtil.nvl(req.getParameter("q10_1"),"6");
			String q10_2 = CommonUtil.nvl(req.getParameter("q10_2"),"6");
			String q10_3 = CommonUtil.nvl(req.getParameter("q10_3"),"6");
			String q10_4 = CommonUtil.nvl(req.getParameter("q10_4"),"6");
			String q10_5 = CommonUtil.nvl(req.getParameter("q10_5"),"6");
			String q10_6 = CommonUtil.nvl(req.getParameter("q10_6"),"6");
			String q10_7 = CommonUtil.nvl(req.getParameter("q10_7"),"6");
			String q11_1 = CommonUtil.nvl(req.getParameter("q11_1"),"6");
			String q11_2 = CommonUtil.nvl(req.getParameter("q11_2"),"6");
			String q11_3 = CommonUtil.nvl(req.getParameter("q11_3"),"6");
			String q11_4 = CommonUtil.nvl(req.getParameter("q11_4"),"6");
			String q11_5 = CommonUtil.nvl(req.getParameter("q11_5"),"6");
			String q11_6 = CommonUtil.nvl(req.getParameter("q11_6"),"6");
			String q11_7 = CommonUtil.nvl(req.getParameter("q11_7"),"6");
			
			String part_total = CommonUtil.nvl(req.getParameter("part_total"));
			
			String part1_sum = CommonUtil.nvl(req.getParameter("part1_sum"),"0");	
			String part1 = CommonUtil.nvl(req.getParameter("part1"));
			
			String part2_sum = CommonUtil.nvl(req.getParameter("part2_sum"),"0");	
			String part2 = CommonUtil.nvl(req.getParameter("part2"));
			
			String part3_sum = CommonUtil.nvl(req.getParameter("part3_sum"),"0");	
			String part3 = CommonUtil.nvl(req.getParameter("part3"));
			
			String part4_sum = CommonUtil.nvl(req.getParameter("part4_sum"),"0");	
			String part4 = CommonUtil.nvl(req.getParameter("part4"));
			
			String part5_sum = CommonUtil.nvl(req.getParameter("part5_sum"),"0");	
			String part5 = CommonUtil.nvl(req.getParameter("part5"));
			
			String part6_sum = CommonUtil.nvl(req.getParameter("part6_sum"),"0");	
			String part6 = CommonUtil.nvl(req.getParameter("part6"));
			
			String result_view_yn = CommonUtil.nvl(req.getParameter("result_view_yn"));
			
			con = (new CommonConnect()).getConnection_ds2();
			con.setAutoCommit(false);
			String[] param=null;
			String queryStr = "call sp_sp0401_modify(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
			param= new String[82];
			param[0] = member_test_code;	
			param[1] = member_id;	
			param[2] = user_id;
			param[3] = q1_1;
			param[4] = q1_2;
			param[5] = q2_1;
			param[6] = q2_2;
			param[7] = q3_1;
			param[8] = q3_2;
			param[9] = q3_3;
			param[10] = q3_4;
			param[11] = q3_5;
			param[12] = q4_1;
			param[13] = q4_2;
			param[14] = q4_3;
			param[15] = q4_4;
			param[16] = q4_5;
			param[17] = q4_6;
			param[18] = q4_7;
			param[19] = q5_1;
			param[20] = q5_2;
			param[21] = q5_3;
			param[22] = q5_4;
			param[23] = q5_5;
			param[24] = q5_6;
			param[25] = q5_7;
			param[26] = q6_1;
			param[27] = q6_2;
			param[28] = q6_3;
			param[29] = q6_4;
			param[30] = q6_5;
			param[31] = q6_6;
			param[32] = q6_7;
			param[33] = q7_1;
			param[34] = q7_2;
			param[35] = q7_3;
			param[36] = q7_4;
			param[37] = q7_5;
			param[38] = q7_6;
			param[39] = q7_7;
			param[40] = q8_1;
			param[41] = q8_2;
			param[42] = q8_3;
			param[43] = q8_4;
			param[44] = q8_5;
			param[45] = q8_6;
			param[46] = q8_7;
			param[47] = q9_1;
			param[48] = q9_2;
			param[49] = q9_3;
			param[50] = q9_4;
			param[51] = q9_5;
			param[52] = q9_6;
			param[53] = q9_7;
			param[54] = q10_1;
			param[55] = q10_2;
			param[56] = q10_3;
			param[57] = q10_4;
			param[58] = q10_5;
			param[59] = q10_6;
			param[60] = q10_7;
			param[61] = q11_1;
			param[62] = q11_2;
			param[63] = q11_3;
			param[64] = q11_4;
			param[65] = q11_5;
			param[66] = q11_6;
			param[67] = q11_7;
			
			param[68] = part_total;
			param[69] = part1_sum;
			param[70] = part1;
			param[71] = part2_sum;
			param[72] = part2;
			param[73] = part3_sum;
			param[74] = part3;
			param[75] = part4_sum;
			param[76] = part4;
			param[77] = part5_sum;
			param[78] = part5;
			param[79] = part6_sum;
			param[80] = part6;
			param[81] = result_view_yn;
			

			
			
			list = DAO.select(con,queryStr,param);
			
			listMap.put("mainContent",list);
			logger.debug("queryStr ==> "+"tstest_modify.query");		     
		     
// 리퀘스트에 모두 담는다.
			req.setAttribute("list_map",listMap);

		}catch (Exception ex) {
			try{
				con.rollback();
			}catch(Exception ee){}
			ex.printStackTrace();
			throw new CommandException(ex.getMessage());
		}finally {
			try{
				if (con!=null) con.setAutoCommit(true);
				if (con!=null) con.close();
			}catch(Exception ee){}
		}
		return next;
	}
	


}
